<template>
  <el-dialog v-model="dialogFormVisible" title="增加订阅">
    <el-form :model="form" ref="ruleFormRef" :rules="rules" label-width="120px">
      <el-form-item label="订阅URL" prop="rssLink">
        <el-input v-model="form.rssLink" autocomplete="off" disabled="true" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" />
      </el-form-item>
      <el-form-item label="博客地址">
        <el-input v-model="form.blogLink" />
      </el-form-item>
      <el-form-item label="文章数量">
        <el-input v-model="form.articleLimit" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="editFollow(fasle)">取消</el-button>
        <el-button type="primary" @click="editFollow(true)"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { editFollow } from "@/common/api/rss";
import { $tip } from "@/base/util/ui";

export default {
  props: {},
  data() {
    return {
      dialogFormVisible: false,
      form: {
        rssLink: "https://r0ad.github.io/atom.xml",
      },
      moreFlag: false,
      rules: {
        rssLink: [
          {
            required: true,
            message: "请输入订阅URL",
            trigger: "change",
          },
        ],
        remark: [
          {
            required: true,
            message: "请输入备注",
            trigger: "change",
          },
        ],
      },
    };
  },
  watch: {},
  methods: {
    init(follow) {
      this.moreFlag = false;
      this.dialogFormVisible = true;
      console.log( JSON.stringify(follow));
      this.form ={
        ...follow
      }
    },
    editFollow(flag) {
      if (flag) {
        if(!this.form.rssLink || !this.form.remark){
          $tip.error("请输入必填内容");
          return false; 
        }
        
        // 增加订阅
        const param = { ...this.form };
        editFollow(param).then((res) => {
          if (res) {
            $tip.success("更新成功");
            this.dialogFormVisible = false;
            this.$emit('submit')
          }
        });
      } else {
        this.dialogFormVisible = false;
      }
    }
  },
};
</script>

<style scoped></style>
